<?php

namespace App\Admin\Controllers;

use App\Admin\Grid\NGrid;
use App\Models\TaskRelatedModel;
use Encore\Admin\Controllers\AdminController;

class TaskRelatedController extends AdminController
{
    public function title(): string
    {
        return '资源管理-资源预览';
    }

    public function grid(): NGrid
    {
        $grid = new NGrid(new TaskRelatedModel);

        $grid->model()->leftJoin('task', 'task_related.task_id', 'task.id')
            ->where('task_id', request()->segment(4))
            ->select([
                'task_related.*',
                'task_name',
            ])->orderByDesc('task_related.id');
        $grid->filter(function ($filter) {
            $filter->disableIdFilter();
            $filter->column(1 / 2, function ($filter) {
                $filter->like('task_related-name', '客户姓名');
                $filter->like('task_related-mobile', __('l.mobile'));
            });
        });
        $grid->column('id', 'ID')->sortable();
        $grid->column('task_name', __('task.taskName'));
        $grid->column('name', '客户姓名');
        $grid->column('gender', __('l.gender'))->display(function () {
            return $this->gender ? '男' : '女';
        });
        $grid->column('age', __('l.age'));
        $grid->column('area', __('task.area'));
        $grid->column('mobile', __('l.mobile'))->display(function() {
            return is_null($this->mobile)?'':maskMobile($this->mobile);
        });
        $grid->column('wechat', __('l.wechat'));
        $grid->column('remark', __('l.remark'))->display(function () {
            if (mb_strlen($this->remark) < 16) return $this->remark;
            else return view('tooltip ', [
                'data' => $this->remark
            ]);
        });
        $grid->disableActions();
        $grid->disableCreateButton();
        return $grid;
    }
}
